package cn.sdpjw.service.impl;

import cn.sdpjw.common.base.basic.InviteCodeGenerateUtil;
import cn.sdpjw.dao.TraderCorpMemberMapper;
import cn.sdpjw.entity.TraderCorpMember;
import cn.sdpjw.service.TraderCorpMemberService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther: liuyuebai
 * @Date: 2024/1/19 08:39
 * @Description:
 */
@Service
public class TraderCorpMemberServiceImpl extends ServiceImpl<TraderCorpMemberMapper, TraderCorpMember> implements TraderCorpMemberService {

    @Override
    public void handleMemberInviteCode() {
        List<TraderCorpMember> traderCorpMembers = baseMapper.listWithoutInviteCode();
        for (TraderCorpMember traderCorpMember:traderCorpMembers){
            // 生成邀请码
            String inviteCode = InviteCodeGenerateUtil.generateByPlatformCorpUser((param) -> baseMapper.selectExistInviteCode(param));
            TraderCorpMember updateMember = new TraderCorpMember();
            updateMember.setId(traderCorpMember.getId());
            updateMember.setMemberInviteCode(inviteCode);
            updateById(updateMember);
        }
    }
}
